package com.liu.audio.asr;

import com.alibaba.dashscope.audio.asr.recognition.Recognition;
import com.alibaba.dashscope.audio.asr.recognition.RecognitionParam;
import java.io.File;

/**
 * 识别类
 */
public class RecognitionTest {

    public static String apiKey = "sk-d1c41de66c074fc686488ab227d32fbe";
    public static void main(String[] args) throws InterruptedException {
        // 创建Recognition实例
        Recognition recognizer = new Recognition();
        // 创建RecognitionParam
        RecognitionParam param =
                RecognitionParam.builder()
                        // 若没有将API Key配置到环境变量中，需将下面这行代码注释放开，并将apiKey替换为自己的API Key
                         .apiKey(apiKey)
                        .model("paraformer-realtime-v2")
                        .format("wav")
                        .sampleRate(16000)
                        .vocabularyId("vocab-Drilling-23782be4a39b44a1a6a117ee246e8e4d")
                        // “language_hints”只支持paraformer-realtime-v2模型
                        .parameter("language_hints", new String[]{"zh"})
                        .build();
        try {
            File file = new File("D:\\workspace\\java-demo\\java-17\\00-source\\ccf21519-b991-4f39-be38-f84b70ba1aa2.wav");

            String call = recognizer.call(param, file);
            System.out.println("识别结果：" + call);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(
                "[Metric] requestId: "
                        + recognizer.getLastRequestId()
                        + ", first package delay ms: "
                        + recognizer.getFirstPackageDelay()
                        + ", last package delay ms: "
                        + recognizer.getLastPackageDelay());
//        System.exit(0);
    }
}